package com.nekonomics
package api.dto.response

import domain.detail.{OrderDetail, OrderItemDetail}
import types.*

import zio.json.*
import java.time.OffsetDateTime

case class OrderDetailDto(
  id: Long,
  buyerName: String,
  createdAt: OffsetDateTime,
  status: OrderStatus,
  totalPrice: Money,
  items: List[OrderItemDetailDto]
) derives JsonEncoder

object OrderDetailDto {
  given Ordering[OrderDetailDto] = Ordering.by((_: OrderDetailDto).createdAt).reverse
  
  def of(order: OrderDetail, items: List[OrderItemDetail])  = {
    OrderDetailDto(
      id  = order.id,
      buyerName = order.buyerName,
      createdAt = order.createdAt,
      status = order.orderStatus,
      totalPrice = order.totalPrice,
      items = items.map(OrderItemDetailDto.of)
    )
  }
  
  
  
  
}
